import Cookies from "js-cookie";

const TokenKey = "admin_token";
const FunctionKey = "admin_function";
const FunctionKey2 = "admin_function2";

export function getToken() {
  return Cookies.get(TokenKey);
}

export function setToken(token) {
  return Cookies.set(TokenKey, token);
}

export function removeToken() {
  return Cookies.remove(TokenKey);
}

export function getFunction() {
  if(Cookies.get(FunctionKey2)){
    return Cookies.get(FunctionKey)+Cookies.get(FunctionKey2);
  }else{
    return Cookies.get(FunctionKey);
  }
}

export function setFunction(functions) {
  Cookies.remove(FunctionKey2);
  if(functions.length>3000){
    Cookies.set(FunctionKey,functions.substring(0,3000));
    Cookies.set(FunctionKey2,functions.substring(3000));
  }else{
    Cookies.set(FunctionKey,functions);
  }
  // return Cookies.set(FunctionKey, functions);
}

export function removeFunction() {
  return Cookies.remove(FunctionKey);
}

export function existFunction(code){
  let functions = JSON.parse(getFunction());
  return functions[code];
}


